#include <cstdio>
#include <cstring>
#define max(a,b) (((a)>(b))?(a):(b))
int n, m, n2, t, d[ 101 ][ 101 ], c[ 16 ], pp[ 16 ], a[ 16 ], f[ 1 << 15 ][ 15 ];

void init( )
{
    int i, j, k, u, v, w;
    scanf("%d%d%d", &n, &m, &t);
    memset( d, 0x3f, sizeof( d ) );
    for ( i = 0; i < m; i++ )
    {
        scanf("%d%d%d", &u, &v, &w);
        if ( d[ u ][ v ] > w )
            d[ u ][ v ] = w;
        if ( d[ v ][ u ] > w )
            d[ v ][ u ] = w;
    }
    for ( i = 1; i <= n; i++ )
        d[ i ][ i ] = 0;
    for ( k = 1; k <= n; k++ )
        for ( i = 1; i <= n; i++ )
            for ( j = 1; j <= n; j++ )
                if ( d[ i ][ j ] > d[ i ][ k ] + d[ k ][ j ] )
                    d[ i ][ j ] = d[ i ][ k ] + d[ k ][ j ];
    scanf("%d", &n2);
    for ( i = 0; i < n2; i++ )
        scanf("%d%d%d", &a[ i ], &c[ i ], &pp[ i ]);
    memset( f, -1, sizeof( f ) );
    f[ 0 ][ 0 ] = t;
}

void work( )
{
    int i, j, k, p, p2;
    for ( i = 1; i < ( 1 << n2 ); i++ )
    {
        for ( j = 0; j < n2; j++ )
        {
            if ( !( i & ( 1 << j ) ) )
                continue;
            p = i ^ ( 1 << j );
            if ( p == 0 )
            {
                if ( d[ 1 ][ a[ j ] ] + pp[ j ] <= t )
                    f[ i ][ j ] = t - d[ 1 ][ a[ j ] ] - pp[ j ] + c[ j ];
            }
            else
            {
                for ( k = 0; k < n2; k++ )
                {
                    if ( !( p & ( 1 << k ) ) )
                        continue;
                    if ( f[ p ][ k ] == -1 ) continue;
                    if ( f[ p ][ k ] >= d[ a[ k ] ][ a[ j ] ] + pp[ j ] )
                        f[ i ][ j ] = max( f[ i ][ j ], f[ p ][ k ] - d[ a[ k ] ][ a[ j ] ] - pp[ j ] + c[ j ] );
                }
            }
        }
    }
    p = ( 1 << n2 ) - 1;
    for ( i = 0; i < n2; i++ )
        if ( f[ p ][ i ] >= d[ a[ i ] ][ 1 ] )
            break;
    if ( i < n2 )
        puts("YES");
    else
        puts("NO");
}

int main( )
{
    int t;
    scanf("%d", &t);
    while ( t-- )
    {
        init( );
        work( );
    }
    return 0;
}
